import React, { Component } from 'react';

import './index.less';

import {
    base,
    toast,
    promptBox
} from 'nc-lightapp-front';
import StaffCardRef from 'src/hrpub/refer/pub/StaffCardRef';
import download from '../../../../../hrpub/common/utils/download/download';
// import language from '../../language';

const {
    NCModal,
    NCButton,
    NCCheckbox,
    NCPopconfirm
} = base;

const {
    Header: ModalHeader,
    Body: ModalBody,
    Footer: ModalFooter
} = NCModal;


class WpsDownLoadModal extends Component {
    constructor(props) {
        super(props);

        this.state = {
            PsnCardData:null,
            pk_rpt_def:'',
        };
        this.selectPsnCard = this.selectPsnCard.bind(this);
        this.closeModal = this.closeModal.bind(this);
        this.openWPS = this.openWPS.bind(this);
    }
    //选择人员卡片
    selectPsnCard(data, v){
        let { pk_rpt_def } = this.state;
        if( v.value === pk_rpt_def ){
            return false;
        }
        console.log('选择完展示的所有数据',data,v)
        this.setState({
            pk_rpt_def: v.value || '',
            PsnCardData: data
        })
    }
    closeModal() {
        this.props.close();
        this.setState({
            pk_rpt_def: '',
            PsnCardData:null
        });
    }
    async openWPS(){
        const {pk_rpt_def} = this.state
        if(!pk_rpt_def) {
            toast({
                color: 'warning',
                content: this.props.language['hi6007-000369'] || '请选择需要下载的人员卡片！'
            })
            return false;
        }
        let postData = {
            "pk_rpt_def":pk_rpt_def,
            "pk_psndocs":this.props.pk_psndoc,
        }
        console.log(postData)
        await download({
            url:'/nccloud/hrhi/rptfef/ReportDownloadFilesAction.do',
            body: postData,
            onResult: (res) => {

            }
        });
  

    }

    render() {
        const {
            wpsInitmodelVisible,
            pk_org,
            language
        } = this.props;

        const {
            PsnCardData
        } = this.state;

        return (
            <NCModal
                show={wpsInitmodelVisible}
                onHide={this.closeModal}
                size="sm"
                className="wps-preview-model"
                backdrop="static"
            >
                <ModalHeader
                    closeButton={true}
                >
                    <span>{language['hi6007-200051'] || '报表浏览'}</span>{/* 国际化处理： 报表浏览*/}
                </ModalHeader>
                <ModalBody>
                    <div className="wpsModelbody">
                    <StaffCardRef
                        onChange={this.selectPsnCard}
                        value={PsnCardData}
                        queryCondition={() => {
                            return {
                                rpt_type: "1",
                                pk_org: pk_org.refpk
                            }
                        }}
                    ></StaffCardRef>
                    </div>
                </ModalBody>
                <ModalFooter>
                    <NCButton
                        colors="primary"
                        onClick={this.openWPS}
                    >
                        {language['hi6007-000362'] || '文件下载'}{/* 国际化处理： 是*/}
                    </NCButton>
                    <NCButton
                        onClick={this.closeModal}
                    >
                        {language['hi6007-000005']}{/* 国际化处理： 取消*/}
                    </NCButton>
                </ModalFooter>
            </NCModal>
        );
    }
}

export default WpsDownLoadModal;
